package com.mengya.ui;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.Window;
import android.widget.TabHost;

import com.gzcwt.entity.Notice;
import com.mengya.gzcwt.R;
import com.mengya.utils.NoticeDBO;
import com.mengya.utils.TabFactory;

public class NoticeActivity extends BaseActivity {

	private TabHost tabHost;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
		setContentView(R.layout.notice);

		/*String result = "";
		try {
			result = new NoticeConnetion().execute().get();
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (ExecutionException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
*/
		NoticeDBO ndbo = new NoticeDBO();
		ndbo.createDB(this);
//		ndbo.setNoticeReaded(207);
		//ndbo.updateNotice(result); //更新公告
		

		List<Notice> historyPublicinfo = new ArrayList<Notice>();
		List<Notice> unreadPublicinfos = new ArrayList<Notice>();
		List<Notice> searchPublicinfos = new ArrayList<Notice>();
		
		
		historyPublicinfo = ndbo.getNoticeHis();//获取历史公告
		unreadPublicinfos = ndbo.getNoticeUnread();//获取未读公告
		searchPublicinfos = ndbo.getNoticeByTime("2013-03-11 06:00:00", "2013-03-11 07:00:00");
		ndbo.closeDB();

		try {
			tabHost = (TabHost) this.findViewById(R.id.TabHost01);
			tabHost.setup();

			tabHost.addTab(tabHost.newTabSpec("tab_1")
					.setContent(new TabFactory(this, unreadPublicinfos,0))
					.setIndicator("最新公告"));
		
			tabHost.addTab(tabHost.newTabSpec("tab_2")
					.setContent(new TabFactory(this,searchPublicinfos,1)) 
					.setIndicator("历史公告"));
			
			tabHost.addTab(tabHost.newTabSpec("tab_3")
					.setContent(new TabFactory(this, historyPublicinfo,2))
					.setIndicator("查看历史"));
			tabHost.setCurrentTab(0);

		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}